package com.vf.admin.miaodong.controller;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppVisitor;
import com.vf.admin.miaodong.service.AfterVisitorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 访客记录
 */
@Controller
@RequestMapping("/after/visitor")
public class AfterVisitorController extends BaseController{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AfterVisitorService appVisitorService;

    /**
     * 访客记录列表
     * @param splitPageBean
     * @param startDate  开始时间
     * @param endDate  结束时间
     * @param nick  用户昵称
     * @param phone  用户手机号
     * @param gustname  来访人昵称
     * @param gustphone  来访用户手机号
     * @param gustsex 来访性别  1、男  2、女  3、未选择  默认3、未选择
     * @return
     */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean,String startDate,String endDate,String nick,String phone,
                       String gustname,String gustphone,Integer gustsex){
        try{
            Map<String,Object> map = new HashMap<>();
            map.put("startDate",startDate);
            map.put("endDate",endDate);
            map.put("nick",nick);
            map.put("phone",phone);
            map.put("gustname",gustname);
            map.put("gustphone",gustphone);
            map.put("gustsex",gustsex);
            List<AppVisitor> list = appVisitorService.list(map,splitPageBean);

            request.setAttribute("list",list);
            request.setAttribute("splitPage",splitPageBean);
            request.setAttribute("startDate",startDate);
            request.setAttribute("endDate",endDate);
            request.setAttribute("nick",nick);
            request.setAttribute("phone",phone);
            request.setAttribute("gustname",gustname);
            request.setAttribute("gustphone",gustphone);
            request.setAttribute("gustsex",gustsex);
            //来访性别  1、男  2、女  3、未选择  默认3、未选择
            Map<Integer,String> sexMap = Constants.getSexMap();
            request.setAttribute("sexMap",sexMap);

            return this.sucess("/web/after/visitor/list");
        }catch (Exception e) {
            logger.error("访客记录列表异常",e);
            return this.error("系统繁忙");
        }
    }

}
